﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _008热水器
{
    /// <summary>
    ///加热器
    /// </summary>
    class Heater
    {
        //定义委托类型
        public delegate void TemperatureDelegate(int temp);
        public event TemperatureDelegate temperatureEvent;//水温事件
        public event TemperatureDelegate alarmEvent;//警报事件
        private int _temperature;//温度
        //烧水
        public void BoilWater()
        {
            for (int i = 20; i <= 100; i++)
            {
                _temperature = i;
                //向外部报水温
                if (temperatureEvent != null)
                    temperatureEvent(_temperature);
                //如果水温大于98度
                if(_temperature >= 98)
                {
                    alarmEvent?.Invoke(_temperature);
                }

            }
                
        }
    }
}
